package com.zhike.b2b.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.saas.struts.form.StaffLoginForm;
import com.saas.sys.bpm.TradeCheckIntf;
import com.saas.sys.bpm.TradeRegIntf;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.log.Logger;

@Controller
public class TradeAction
{
	@Resource(name="trade")
	TradeRegIntf tri ;
	
	@Resource(name="checktrade")
    TradeCheckIntf tci ;
	
  @RequestMapping("/doTradeReg.do")
  public String execute(HttpServletRequest request)
  {
	StaffLoginForm model = new StaffLoginForm();
	
    Logger log = new Logger(this);
    Buffers params = new Buffers();
    Buffers res = new Buffers();
    Buffers outParams = new Buffers();
    
    HttpSession session = request.getSession();
    params.convert(request, model, session);
    params.setBean(model);
      
    tci.execTradeCheck(params);
    outParams = tci.getOutBuffer();
    ArrayList localArrayList2 = outParams.buffersToBuffer(tci.getOutBuffer());
    request.setAttribute("buffer", params);
    if (outParams.getInt("RESULT_CODE") != 0)
    {
      request.setAttribute("outBuffer", outParams);
      request.setAttribute("backQ", localArrayList2);
      return "/dialog/fail";
    }
    res = tri.tradeRegInfo(params);
    log.LOG_INFO("业务登记结束！");
    if (res.getInt("RESULT_CODE") == 0)
    {
      log.LOG_INFO("开始记录业务日志......");
      tri.setCheck_tag("1");
      tri.tradeRegInfo(res);
      log.LOG_INFO("业务日志记录结束！");
    }
    log.LOG_INFO("开始设置返回数据.......");
    Object seesionData = res.buffersToBuffer(res);
    request.setAttribute("backQ", seesionData);
    log.LOG_INFO("全部业务结束，转向表示层！");
    if (res.getInt("RESULT_CODE") == 0)
      return "/dialog/tsuccess";
    return "/dialog/fail";
  }
}

